package com.nuo.common.web.exception;

import com.nuo.common.core.result.IResultCode;
import lombok.Getter;

/**
 * @author LGC
 * @date 2021/7/23 14:00
 */
@Getter
public class BizException extends RuntimeException {

    private static final long serialVersionUID = -8866851195120593503L;

    /**
     * 业务异常类型
     */
    private IResultCode resultCode;

    /**
     * 异常msg
     */
    private String msg;

    public BizException() {

    }

    public BizException(String message){
        super(message);
    }

    public BizException(String message, Throwable cause){
        super(message, cause);
    }

    public BizException(Throwable cause){
        super(cause);
    }

    public BizException(IResultCode resultCode) {
        super(resultCode.getMsg());
        this.resultCode = resultCode;
        this.msg = resultCode.getMsg();
    }

    public BizException(IResultCode resultCode, String msg) {
        super(msg);
        this.resultCode = resultCode;
        this.msg = msg;
    }

    public BizException(IResultCode resultCode, Throwable throwable) {
        super(throwable.getMessage(), throwable);
        this.resultCode = resultCode;
        this.msg = resultCode.getMsg();
    }

    public BizException(IResultCode resultCode, String msg, Throwable throwable) {
        super(msg, throwable);
        this.resultCode = resultCode;
        this.msg = msg;
    }

    public BizException(IResultCode resultCode, String code, String msg) {
        super(String.format("%s：%s", code, msg));
        this.resultCode = resultCode;
        this.msg = String.format("%s：%s", code, msg);
    }
}
